## Authors: Alexander Herzog and Kenneth Benoit
## Date: May 30, 2015
## Replication file for JOP article "The Most Unkindest Cuts: Speaker Selection and Expressed Government Dissent During Economic Crisis"

rm(list = ls(all = TRUE))


### DATA ##############################
load("./generated_data/working_data_speakers.RData")
########################################

data <- dataSub

# groups
data$group <- NA
data$group[data$position=="Opposition"] <- 1
data$group[data$position=="Govt backbencher"] <- 2
data$group[data$position %in% c("Taoiseach","Tánaiste","Minister","Minister of State")] <- 3

data$group <- factor(data$group, labels=c("Opposition\nspeaker","Government\nbackbencher","Cabinet\nmember"))


# periods with full description
data$periodLong <- NA
data$periodLong[data$period=="FF Minority Govt"] <- "FF Minority Government\n(1987-1988)"
data$periodLong[data$period=="FF Coal"] <- "FF Coalitions\n(1989-1994)"
data$periodLong[data$period=="FG-Lab-DL Rainbow Coal"] <- "FG-Lab-DL Rainbow Coalition\n(1995-1997)"
data$periodLong[data$period=="FF-led Boom Years"] <- "FF-led Boom Years\n(1998-2008)"
data$periodLong[data$period=="FF-Gr Crisis Years"] <- "FF-Greens Crisis Years\n(2009-2011)"
data$periodLong[data$period=="FG-Lab Crisis Years"] <- "FG-Lab Crisis Years\n(2012-2013)"  


data$periodLong <- factor(data$periodLong,
                          levels=c("FF Minority Government\n(1987-1988)",
                              "FF Coalitions\n(1989-1994)",
                              "FG-Lab-DL Rainbow Coalition\n(1995-1997)",
                              "FF-led Boom Years\n(1998-2008)",
                              "FF-Greens Crisis Years\n(2009-2011)",
                              "FG-Lab Crisis Years\n(2012-2013)"))


# Boxplots by government periods and width proportional to group size
# -------------------------------------------------------------------
pdf(file="./plots/boxplots_by_government_periods.pdf", height=15, width=10)
par(mfrow=c(3,3))
for (i in levels(data$periodLong)) {
    d <- subset(data, data$periodLong==i)
    boxplot(textscore~group, data=d,
            main="",
            xlab="",
            ylim=c(-1,1),
            ylab="Wordscores score",
            varwidth=TRUE,
            axes=FALSE,
            cex.lab=1.25
            )
    title(i)
    axis(1, at=d$group, labels=d$group, cex.axis=1.1, padj=0.5)
    axis(2, at=seq(-1,1,0.5))
    box(lty=1)
}

dev.off()
